<!-- ZmList 滚动加载 -->
<template>
  <van-list
    :finished-text="FinishedText"
    :immediate-check="immediateCheck"
    v-bind="$attrs"
    v-model="Value"
    v-on="listeners"
  >
    <slot />
    <zm-no-data
      :class="noDataClass"
      :desc="desc"
      :type="type"
      v-if="isNoData"
    />
  </van-list>
</template>

<script>
export default {
  name: 'ZmList',
  props: {
    value: {
      type: Boolean,
      required: true
    },
    list: {
      type: Array
    },

    immediateCheck: {
      type: Boolean,
      default: true
    },
    finishedText: {
      type: String,
      default: '没有更多数据～'
    },
    type: {
      type: String
    },
    desc: String,
    noDataClass: {
      type: String,
      default: 'pt40 pb20'
    }
  },
  data() {
    return {};
  },

  computed: {
    Value: {
      set(v) {
        this.$emit('input', v);
      },
      get() {
        return this.value;
      }
    },

    FinishedText() {
      let txt = this.finishedText || '没有更多数据～';
      if (this.list && !this.list.length) {
        txt = '';
      }
      return txt;
    },

    isNoData() {
      return this.list && this.$attrs.finished && !this.value && !this.list.length;
    },

    // 监听所有绑定事件
    listeners() {
      const listeners = {};
      const $listeners = this.$listeners;
      const exclude = ['input'];
      for (const i in $listeners) {
        if (!exclude.includes(i)) {
          listeners[i] = $listeners[i];
        }
      }
      return listeners;
    }
  },
  methods: {
    // 初始化方法
    init() {}
  }
};
</script>
<style lang="scss" scoped></style>
